﻿using ZquenceStudio3Host.DspPlugins.Synthesizers.Nodesizer.Engine;

namespace DefaultDspPlugins.Common.Modulizer.Engine.Modules.Waveforms
{
    [ModuleDisplay("Wave Custom")]
    public class CustomWaveFormModule : BaseModule
    {
        private short[] UserWaveform = new short[1024];
        private double[] InternalWaveform = new double[ModuleOutput.WAVEFORM_BUFFER_LENGTH];

        public readonly ModuleOutput OutWaveform;

        public readonly ModuleParameter ParameterWaveform;

        public int Length { get { return UserWaveform.Length; } }

        public short this[int index]
        {
            get
            {
                return UserWaveform[index];
            }
            set
            {
                UserWaveform[index] = value;
            }
        }

        public CustomWaveFormModule(ModuleManager manager)
            : base(manager)
        {
            AddOutput(OutWaveform = new ModuleOutput("Waveform", IOType.Waveform, this));
        }

        public override void Process()
        {
        }

        public void SetUserWaveform()
        {
            for (int i = 0; i < InternalWaveform.Length; i++)
            {
                int i1 = i;
                int i2 = (int)(UserWaveform.Length / (double)InternalWaveform.Length * i);
                InternalWaveform[i1] = UserWaveform[i2] / (double)short.MaxValue;
            }
        }
    }
}
